#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int n;
int arr[1000];
int main()
{
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			arr[i] = i + 1;
		}
		do {
			for (int i = 0; i < n; i++) {
				cout << setw(5) << arr[i];
			}
			cout << endl;
		} while (next_permutation(arr, arr + n));
	}
	return 0;
}